package ro.dandanciu.webgallery.util;

/**
 * Class for reading setting from the <code>application.properties</code>.
 * <br><br>
 * Each setting in this file must appear for each environment (DEV, UAT, PROD ...),
 * except the first one which is the one setting the active environment.
 * 
 * @author Dan Danciu
 */
public class SettingsReader extends PropertyReader {

	/**
	 * Constant indicating the name of the file for the settings.
	 */
	private static final String SETTINGS_RESOURCE_FILE = "application";

	/**
	 * Constant for the key indicating the active environment.
	 */
	private static final String ENVIRONMENT_KEY = "active.environment";
	
	/**
	 * Constant which indicates the separator for the words in the key.
	 */
	private static final String KEY_SEPARATOR = ".";

	/**
	 * Field which shows the active environment.
	 * Default to: 'DEV'. 
	 */
	private String environment = "DEV";
	
	/**
	 * Constructs an object for reading application settings. 
	 */
	public SettingsReader() {
		super(SETTINGS_RESOURCE_FILE);
		environment = super.getMessage(ENVIRONMENT_KEY);
	}

	/**
	 * Use this method to read an application setting which has arguments.
	 * @param key the key under which the setting is stored.
	 * @param args the list of arguments for the setting.
	 * @return the setting read for the active environment with the arguments replaced.
	 */
	public String getMessage(String key, Object... args) {
		return super.getMessage(key + KEY_SEPARATOR + environment, args);
	}

	/**
	 * Use this method to read an application setting.
	 * @param key the key under which the setting is stored.
	 * @return the setting read for the active environment.
	 */
	public String getMessage(String key) {
		return super.getMessage(key + KEY_SEPARATOR + environment);
	}

}
